<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <f:view contentType="text/html">
        <h:head>
            <f:facet name="first">
                <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
                <title>PrimeFaces</title>
            </f:facet>
        </h:head> 

        <h:body>
            <ui:composition template="./template.xhtml">
                <ui:define name="top">

                </ui:define>
                <ui:define name="left">
                    <h:form >

                        <p:menu my="true" style="width:200px">
                            <p:submenu label="Navigation Employé" >  
                                <p:menuitem value="Les employés" action="#{redirectionBean.getRedirectionListeAmploye}" icon="ui-icon-home"
                                            styleClass="#{view.viewId == '/listeTravailleur.xhtml' || 
                                                          view.viewId == '/ajouterUnTravailleur.xhtml' || 
                                                          view.viewId == '/detailTravailleur.xhtml' ||
                                                          view.viewId == '/editerUnTravailleur.xhtml' ? 'ui-state-active' : ''}"
                                            />  
                                
                            </p:submenu>
                            <p:submenu label="Navigation Mission">  
                                <p:menuitem value="Gestion des missions" action="#{redirectionBean.getRedirectionGestionMission}" icon="ui-icon-suitcase" 
                                            styleClass="#{view.viewId == '/gestionMission.xhtml' ? 'ui-state-active' : ''}"
                                            />   
                            </p:submenu>  
                            <p:submenu label="Navigation Réglage">  
                                <p:menuitem value="Réglage formulaire" action="#{redirectionBean.getRedirectionGeglageformulaire}" icon="ui-icon-gear"
                                            styleClass="#{view.viewId == '/reglageformulaire.xhtml' ? 'ui-state-active' : ''}"
                                            />  
                            </p:submenu>  
                        </p:menu> 

                    </h:form>
                </ui:define>
                <ui:define name="content">

                    <h:form id="formMessage">
                        <p:growl id="message" />
                    </h:form>
                    <h:form id="formeTreeGestionDesMission">
                        <p:panel header="Employé" style="width: 95%">
                            <f:facet name="header">
                                Gestion des Missions
                                <p:menuButton  style="float: right;" value="Créer">  
                                    <p:menuitem value="Une Mission"  update=":formNouveauMission"
                                                immediate="true"
                                                action="#{gestionMissionBean.initialisationSaisie}"
                                                oncomplete="nouveauMissionDialog.show()" icon="ui-icon-suitcase"/>  
                                    <p:menuitem value="Un Département" 
                                                immediate="true"
                                                action="#{gestionMissionBean.initialisationSaisie}"
                                                oncomplete="nouveauDepartementDialog.show()" icon="ui-icon-lightbulb"/>  
                                    <p:menuitem value="Une Equipe" icon="ui-icon-pin-w" 
                                                update=":formNouveauEquipeCourver:formNouveauEquipe"
                                                immediate="true"
                                                action="#{gestionMissionBean.initialisationSaisie}"
                                                oncomplete="nouveauEquipeDialog.show()"
                                                />  

                                </p:menuButton>

                                <p:commandButton id="viewDetailTravailleur" 
                                                 style="float: right;" value="Voir détails" icon="ui-icon-search"
                                                 update=":formeTreeGestionDesMission:documentPanelDetailElement" oncomplete="documentDialogDetailElement.show()"
                                                 >
                                </p:commandButton>
                            </f:facet>
                            <p:treeTable id="tableTeeElement" value="#{gestionMissionBean.root}"  var="elementArbre"  
                                         selection="#{gestionMissionBean.selectedNode}" selectionMode="single">  

                                <f:facet name="header">  
                                    Liste des Missions, Département, Equipes

                                </f:facet>  

                                <p:column style="width:50%">  
                                    <f:facet name="header">  
                                        Nom  
                                    </f:facet>  
                                    <h:outputText value="#{elementArbre.nomElement}" style="font-weight:bold"/>  
                                </p:column>                            

                                <p:column style="width:40%">  
                                    <f:facet name="header">  
                                        Type  
                                    </f:facet>  
                                    <h:outputText value="#{elementArbre.nameTypeElement}" />  
                                </p:column> 

                                <p:column >
                                    <f:facet name="header">
                                        Activé
                                    </f:facet>
                                    <h:outputText value="#{elementArbre.etatElement == true ? 'Oui' : 'Non'}" styleClass="#{elementArbre.etatElement == true ? 'verte':'rouge'}" />                                     
                                </p:column>
                            </p:treeTable> 
                            
                        </p:panel>
                        <p:dialog id="dialogDetailElement" header="Détails" 
                                  resizable="false" hideEffect="explode" showEffect="slide" widgetVar="documentDialogDetailElement" >  
                            <p:outputPanel id="documentPanelDetailElement" >  
                                <h:panelGrid  columns="2" cellpadding="5" rendered="#{not empty gestionMissionBean.selectedNode}">  
                                    <h:outputLabel for="name" value="Name: " />  
                                    <h:outputText id="name" value="#{gestionMissionBean.selectedNode.data.nomElement}" style="font-weight:bold" /> 
                                    <h:outputLabel for="type" value="Type :" />  
                                    <h:outputText id="type" value="#{gestionMissionBean.selectedNode.data.nameTypeElement}" style="font-weight:bold" />  
                                </h:panelGrid>  
                            </p:outputPanel>  
                        </p:dialog> 
                    </h:form>

                    <p:dialog header="Créer une mission" widgetVar="nouveauMissionDialog" resizable="false" id="nouveauMissionDialogId"  
                              hideEffect="explode" showEffect="slide" >  
                        <h:form id="formNouveauMission">
                            <h:panelGrid columns="2">
                                <h:outputLabel value="Code de la mission:" for="inputCreerMission" />
                                <p:inputText id="inputCreerMission" value="#{gestionMissionBean.cvMission.idmission}" 
                                             title="Mission" required="true" 
                                             />
                                <h:outputText />
                                <p:commandButton value="Créer" icon="ui-icon-check"
                                                 action="#{gestionMissionBean.voidCreerMission}"
                                                 update=":formMessage:message, :formNouveauMission, :formeTreeGestionDesMission:tableTeeElement"
                                                 oncomplete="handleCreerMissionRequest(xhr, status, args)"
                                                 />                        
                            </h:panelGrid>
                        </h:form>
                    </p:dialog>

                    <p:dialog header="Créer un département" widgetVar="nouveauDepartementDialog" resizable="false" id="nouveauDepartementDialogId"  
                              hideEffect="explode" showEffect="slide" >  
                        <h:form id="formNouveauDepartement">
                            <h:panelGrid columns="2">
                                <p:outputLabel value="Mission :" for="missionListe" />
                                <p:selectOneMenu id="missionListe" style="width:200px" required="true" value="#{gestionMissionBean.cvMission}" converter="missionConverter">  
                                    <f:selectItem itemLabel="Selectionne mission" itemValue="" />  
                                    <f:selectItems value="#{gestionMissionBean.listeMission}" var="mission" itemLabel="#{mission.idmission}" itemValue="#{mission}"/>  

                                </p:selectOneMenu>  

                                <h:outputLabel value="Nom du département:" for="inputDepartement" />
                                <p:inputText id="inputDepartement" value="#{gestionMissionBean.cvListedepartement.nomdepartement}" 
                                             title="Département" required="true" 
                                             />
                                <h:outputText />
                                <p:commandButton value="Créer" icon="ui-icon-check"
                                                 action="#{gestionMissionBean.voidCreerDepartement}"
                                                 update=":formMessage:message, :formNouveauDepartement, :formeTreeGestionDesMission:tableTeeElement"
                                                 oncomplete="handleCreerDepartementRequest(xhr, status, args)"
                                                 />                        
                            </h:panelGrid>
                        </h:form>
                    </p:dialog>
                    <h:form id="formNouveauEquipeCourver">
                    <p:dialog header="Créer une equipes" widgetVar="nouveauEquipeDialog" resizable="false" id="nouveauEquipeDialogId"  
                              hideEffect="explode" showEffect="slide" >  
                        <h:form id="formNouveauEquipe">
                            <h:panelGrid columns="2">
                                <p:outputLabel value="Mission :" for="missionListe2" />
                                <p:selectOneMenu id="missionListe2" style="width:200px" required="true" value="#{gestionMissionBean.cvMission}" converter="missionConverter">  
                                    <f:selectItem itemLabel="Selectionne mission" itemValue="" />  
                                    <f:selectItems value="#{gestionMissionBean.listeMission}" var="mission" itemLabel="#{mission.idmission}" itemValue="#{mission}"/>  
                                    <p:ajax update="departementliste"  
                                            listener="#{gestionMissionBean.handleMissionChange}" />  
                                </p:selectOneMenu>  

                                <p:outputLabel value="Departement :" for="departementliste" />
                                <p:selectOneMenu id="departementliste" style="width:200px" required="true" value="#{gestionMissionBean.cvListedepartement}" converter="departementConverter">  
                                    
                                    <f:selectItem itemLabel="Selectionner departement" itemValue="" />  
                                    <f:selectItems value="#{gestionMissionBean.departementListeHand}" var="departement" itemLabel="#{departement.nomdepartement}" itemValue="#{departement}" />  
                                     
                                </p:selectOneMenu> 

                                <h:outputLabel value="Nom de l'equipe:" for="inputEquipe" />
                                <p:inputText id="inputEquipe" value="#{gestionMissionBean.cvEquipedepartement.equipe}" 
                                             title="Equipe" required="true" 
                                             />
                                <h:outputText />
                                <p:commandButton value="Créer" icon="ui-icon-check"
                                                 action="#{gestionMissionBean.voidCreerEqupe}"
                                                 
                                                 update=":formMessage:message, :formNouveauEquipeCourver:formNouveauEquipe, :formeTreeGestionDesMission:tableTeeElement"
                                                 oncomplete="handleCreerEquipetRequest(xhr, status, args)"
                                                 />                        
                            </h:panelGrid>
                        </h:form>
                    </p:dialog>
                    </h:form>
                    <script type="text/javascript">
                        function handleCreerMissionRequest(xhr, status, args) {
                            if (args.validationFailed || !args.status) {
                                //alert(args.message);
                            } else {
                                nouveauMissionDialog.hide();

                            }
                        }
                        function handleCreerDepartementRequest(xhr, status, args) {
                            if (args.validationFailed || !args.status) {
                                //alert(args.message);
                            } else {
                                nouveauDepartementDialog.hide();

                            }
                        }
                        function handleCreerEquipetRequest(xhr, status, args) {
                            if (args.validationFailed || !args.status) {
                                //alert(args.message);
                            } else {
                                nouveauEquipeDialog.hide();

                            }
                        }
                    </script>
                </ui:define>
            </ui:composition>
        </h:body>

    </f:view>
</html>

